// /**游戏数据 */
// /**调试 */

import { _decorator, JsonAsset, v2 } from 'cc';
import { YangLeGeYang_LevelList } from "../../../../Script/Game/DanCiPeiDui/YangLeGeYang_LevelList";
import { bdlMgr } from "../../../../Script/Manager/BundleManager_S";
import { SSS_Consts } from "../../../../Script/Data/SSS_Consts";
import { YangLeGeYang_GameStorage } from "./YangLeGeYang_GameStorage";

export class YangLeGeYang_GameData {
    //    /**单个宽度 */
    public static CellWidth: number = 82// 90;
    //    /**单个高度 */
    public static CellHeight: number = 90;
    //    /**单个高度 */
    public static CellHeight2: number = YangLeGeYang_GameData.CellHeight - 13;
    //    /**关卡层数 */
    public static Leve_l_layer_count: number = 50;
    public static Leve_2_layer_count: number = 50;
    public static MapData: any;
    public static CurrentLevel: number = 0;
    public static MapData_CurrentLevel: any = [];
    public static CurrentLevelDataList = [];
    public static Card_types: any = [];
    //    /**操作台块数 */
    public static OperatePanelGridNumber: number = 7;
    //    /**操作台数据 */
    public static MapData_Operate: any = [];
    //    /**空地数据 */
    public static MapData_EmptyLand: any = [];
    //    /**上一个点击Index */
    public static LastClickCardIndex: number;
    //    // 每关道具数量
    public static LevelUseItemNumber: number[] = [1, 1, 1];
    //    // 复活数量
    public static LevelRebornNumber: number = 1;
    public static CurrentLevelIndex: number = 1;
    public static CurrentLevelData: any = {};
    public static isDead: boolean = false;
    public static ClearData() {
        // DanLeGeCi_GameData.CurrentLevel = 0;

        YangLeGeYang_GameData.MapData_CurrentLevel = [];
        YangLeGeYang_GameData.MapData_Operate = [];
        YangLeGeYang_GameData.MapData_EmptyLand = [];
        YangLeGeYang_GameData.isDead = false;

        YangLeGeYang_GameData.LevelUseItemNumber = [1, 1, 1];
    }
    public static InitData() {

    }
    //    // 羊了个羊调关卡
    static Get_CurrentLevelIndex() {
        // return 2
        return YangLeGeYang_GameStorage.data.current_level;
    }
    static Get_SpriteIndex() {
        // return 1
        let levelCount = YangLeGeYang_GameData.Get_LevelList().wordList.length // 3;
        let currentIndex = (YangLeGeYang_GameStorage.data.current_level % levelCount) + 0;
        return currentIndex;
    }
    static Set_CurrentLevelIndex(_value) {
        YangLeGeYang_GameStorage.data.current_level = _value;
        YangLeGeYang_GameStorage.saveData();
    }
    public static GetCurrentLevelData() {
        // let data = {
        //     id: "clothing", en: "clothing", cn: "服饰", root: "clothing",
        //     list: [
        //         `tile_c1_t1`, `tile_c1_t2`, `tile_c1_t3`, `tile_c1_t4`, `tile_c1_t5`,
        //         `tile_c2_t1`, `tile_c2_t2`, `tile_c2_t3`, `tile_c2_t4`, `tile_c2_t5`,
        //         `tile_c3_t1`, `tile_c3_t2`, `tile_c3_t3`, `tile_c3_t4`, `tile_c3_t5`,
        //     ],
        // }
        let data = {
            id: "clothing", en: "clothing", cn: "服饰", root: "clothing",
            list: [
                `葡萄`,
                `橙子`,
                `荔枝`,
                `蓝莓`,
                `猕猴桃`,
                `苹果`,
                `椰子`,
                `哈密瓜`,
                `西红柿`,
                `西瓜`,
                `榴莲`,
            ],
        }

        return data;
    }
    public static async InitLevelData(_CurrentLevel) {
        // DanLeGeCi_GameData.CurrentLevel = _CurrentLevel;
        // DanLeGeCi_GameData.LevelUseItemNumber = [1, 1, 1];
        // DanLeGeCi_GameData.LevelRebornNumber = 1;

        let levelList = YangLeGeYang_GameData.Get_LevelList();
        // YangLeGeYang_GameData.CurrentLevelData = levelList.wordList[YangLeGeYang_GameData.CurrentLevelIndex];


        // YangLeGeYang_GameData.CurrentLevelData = levelList.wordList[YangLeGeYang_GameData.Get_CurrentLevelIndex()];
        YangLeGeYang_GameData.CurrentLevelData = levelList.wordList[YangLeGeYang_GameData.Get_SpriteIndex()];



        // YangLeGeYang_GameData.CurrentLevelData = YangLeGeYang_GameData.GetCurrentLevelData();


        // console.log(`DanLeGeCi_GameData.CurrentLevelIndex`, DanLeGeCi_GameData.CurrentLevelIndex)
        // console.log(`DanLeGeCi_GameData.CurrentLevelData`, DanLeGeCi_GameData.CurrentLevelData)

        YangLeGeYang_GameData.Card_types = YangLeGeYang_GameData.CurrentLevelData.list;
        // // console.log(`DanLeGeCi_GameData.Card_types`, DanLeGeCi_GameData.Card_types);
        // // console.log(`DanLeGeCi_GameData.MapData`, DanLeGeCi_GameData.MapData);
        // console.log(`DanLeGeCi_GameData.CurrentLevel`, DanLeGeCi_GameData.CurrentLevel);
        // // console.log(`DanLeGeCi_GameData.MapData_CurrentLevel--->`, DanLeGeCi_GameData.MapData_CurrentLevel);
        // console.log(`MapData_Level`, MapData_Level);
        // // console.log(`MapData_Level_index`, MapData_Level_index);

        // {
        //     let random = randomRangeInt(0, MapData_Level.length);
        //     let layer = MapData_Level[random].level;
        //     let temp_array = layer.concat()// DanLeGeCi_GameData.CurrentLevelData.layer; // MapData_Level[MapData_Level_index].concat();
        //     // console.log(`temp_array`, temp_array)

        //     temp_array.reverse();
        //     // console.log(`temp_array`, temp_array)
        // }


        YangLeGeYang_GameData.MapData_CurrentLevel = [];


        // let array_level = [
        //     // 2,
        //     2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
        //     16, 17, 20, 22, 23, 25, 26, 29, 32, 37,
        //     43, 46, 48, 51, 52, 53, 54, 58, 60, 63,
        //     65, 69, 71, 75, 78, 79, 81, 82, 83, 84,
        //     87, 89, 90, 91, 92, 94, 96, 105, 106, 109,
        //     110, 111, 113, 114, 116, 119, 120, 123, 127, 128,
        //     129, 130, 148, 149, 150, 160, 163, 166, 172, 173,
        //     185, 202, 206, 210, 211, 216, 218, 222, 225, 228,
        //     230, 231, 232, 233, 244, 245, 246, 247, 248, 249,
        //     250, 257, 262, 265, 268, 272, 275, 276, 278, 279,
        //     280, 281, 285, 286, 287, 288, 293, 295, 296, 297,
        //     298, 299, 300, 304, 306, 307, 308, 310, 311, 312,
        //     313, 314, 315, 316, 319, 325, 326, 327, 329, 330,
        //     331, 332, 333, 334, 340, 341, 349, 351, 359, 360,
        // ];


        //临时测试
        // DanLeGeCi_GameData.CurrentLevelIndex = _CurrentLevel;
        //临时测试
        // let level = array_level[DanLeGeCi_GameData.CurrentLevelIndex]

        // let level = array_level[randomRangeInt(0, array_level.length)];


        // let level = YangLeGeYang_GameData.CurrentLevelIndex + 1
        let level = YangLeGeYang_GameData.Get_CurrentLevelIndex() + 1


        let num = (level).toString().padStart(4, '0');
        let name = `Level/Level_${num}`

        // console.log(`name`, name);

        // 0001
        let level_json = await bdlMgr.getRes<JsonAsset>(SSS_Consts.BundleName.JSON, name, JsonAsset)
        // console.log(`level_json`, level_json);
        // bdlMgr.getRes<JsonAsset>(SSS_Consts.BundleName.JSON, name, JsonAsset).then(level => {

        // console.log(`res`, level.json);

        for (let index = 0; index < level_json.json.length; index++) {
            const item = level_json.json[index];

            let layer = await bdlMgr.getRes<JsonAsset>(SSS_Consts.BundleName.JSON, `Layer/${item}`, JsonAsset)
            // bdlMgr.getRes<JsonAsset>(SSS_Consts.BundleName.JSON, `Layer/${item}`, JsonAsset).then(layer => {
            // console.log(`layer`, layer.json);

            // const itemdata_MapData_CurrentLevel = temp_array[index];
            const layerData = layer.json.cards; //MapData_Layer[itemdata_MapData_CurrentLevel];

            // console.log(`itemdata_MapData_CurrentLevel层====`, itemdata_MapData_CurrentLevel);
            // console.log(`layerData`, layerData);
            for (let index_2 = 0; index_2 < layerData.length; index_2++) {
                const itemdata_layerData = layerData[index_2];
                // console.log(`itemdata_layerData`, itemdata_layerData);

                let item: any = {};
                item.list_index = YangLeGeYang_GameData.MapData_CurrentLevel.length;
                // item.card_type = 0;
                item.card_layer = index + 1;
                item.card_pos = v2(itemdata_layerData.x, itemdata_layerData.y);
                item.isShowFullCover = itemdata_layerData.isShowFullCover === true ? true : false;
                YangLeGeYang_GameData.MapData_CurrentLevel.push(item);

                // console.log(`item`, item);
            }
            // });
        }
        // });
    }
    public static Get_LevelList() {
        return YangLeGeYang_LevelList;
    }
}

window['YangLeGeYang_GameData'] = YangLeGeYang_GameData;